#include "../include/FireworkParticle.h"

#include <raymath.h>

#include "../include/utilities.h"

void FireworkParticle::update(const std::chrono::nanoseconds& delt) {
	if (m_oldPos.size() > m_trailLength) {
		m_oldPos.pop_front();
	}
	if (m_trailLength > 0) {
		m_oldPos.push_back(m_pos);
	}
	
	Particle::update(delt);
	
	if (m_oldPos.size() > 0) {
		Vector3 vertexPos = *m_oldPos.begin();
		Vector3 normal = Vector3Normalize(Vector3Subtract(vertexPos, m_pos));
		m_circlePos = getNormalCirclePos(m_pos, m_radius, normal, 0, 360, 5);
	}
}

void FireworkParticle::draw() {
	if(m_state == ParticleState::Done) {
		return;
	}
	
	Particle::draw();
	
	if (m_oldPos.size() > 0) {
		Vector3 vertexPos = *m_oldPos.begin();
		for (auto it = m_circlePos.begin(); it != m_circlePos.end(); ++it) {
			DrawLine3D(*it, vertexPos, m_color);
		}
	}
}
